import { ConnectionProvider, WalletProvider } from '@solana/wallet-adapter-react';
import { WalletModalProvider } from '@solana/wallet-adapter-react-ui';
import { PhantomWalletAdapter, SolflareWalletAdapter } from '@solana/wallet-adapter-wallets';
import { clusterApiUrl } from '@solana/web3.js';

// 创建连接到Solana网络的实例
const endpoint = clusterApiUrl('devnet');  // 或者 'mainnet-beta' 等

// 设置支持的钱包适配器
const wallets = [
  new PhantomWalletAdapter(),
  new SolflareWalletAdapter(),
  // 可以添加更多适配器
];

const SolanaProvider = ({ children }: { children: React.ReactNode }) => {
  return (
    <ConnectionProvider endpoint={endpoint}>
      <WalletProvider wallets={wallets} autoConnect>
        <WalletModalProvider>{children}</WalletModalProvider>
      </WalletProvider>
    </ConnectionProvider>
  );
};

export default SolanaProvider;